package com.foxire.interface3;

public class ClassDataInterImpl2 implements ClassDatainter{
    private Student[] students;// 存储学生对象信息
    public ClassDataInterImpl2(Student[] students){
        this.students = students;
    }

    @Override
    public void printAllStudentInfos() {
        int malecount = 0;
        for(int i = 0; i < students.length; i++){
            Student s = students[i];
            System.out.println(s.getName()+ " " + s.getScore() + " " + s.getSex());
            if(students[i].getSex() == '男'){
                malecount++;
            }
        }
        System.out.println("男生个数：" + malecount);
        System.out.println("女生个数：" + (students.length - malecount));
    }

    @Override
    public void printAverageScore() {
        System.out.println("平均分：");
        Student s1 = students[0];
        double sum = s1.getScore();
        double max = s1.getScore();
        double min = s1.getScore();
        for (int i = 1; i < students.length; i++){
            Student s = students[i];
            sum += s.getScore();
            if(s.getScore() > max){
                max = s.getScore();
            }
            if(s.getScore() < min){
                min = s.getScore();
            }
        }
        System.out.println("最高分：" + max);
        System.out.println("最低分：" + min);
        System.out.println("平均分：" + (sum-max-min)/(students.length-2));
    }
}
